package cn.teaey.apns.protocol;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
/**
 * User: Teaey
 * Date: 13-8-30
 */
public abstract class Payload
{
    private final        Map<String, Object> root       = new HashMap<String, Object>();
    private static final AtomicInteger       IDENTIFIER = new AtomicInteger(Integer.MIN_VALUE);
    private static final int                 DEF_EXPIRY = (int) TimeUnit.DAYS.toSeconds(1);
    private final        int                 identifier = IDENTIFIER.incrementAndGet();
    /**
     *
     */
    private              int                 expiry     = ((int) System.currentTimeMillis() / 1000) + DEF_EXPIRY;
    protected Object addDictionary(String key, Object value)
    {
        return root.put(key, value);
    }
    public Object removeDictionary(String key)
    {
        return root.remove(key);
    }
    public String toJsonString()
    {
        return JsonParser.toJsonString(root);
    }
    public byte[] toJsonBytes()
    {
        return toJsonString().getBytes(Protocal.DEF_CHARSET);
    }
    public int getIdentifier()
    {
        return identifier;
    }
    public int getExpiry()
    {
        return expiry;
    }
    public void setExpiry(int expiry)
    {
        this.expiry = expiry;
    }
}
